package main;
//为了能够让数据保存到文件
import java.io.Serializable;
//Serializable 序列化数据，方便处理数据
public abstract class Product implements Serializable {
    private String productId;
    private String name;
    private double price;
    
    public Product(String productId, String name, double price) throws InvalidPriceException {
        this.productId = productId;
        this.name = name;
        //确保价格必须得大于0，不然提示错误
        if (price <= 0) {
            throw new InvalidPriceException("价格必须大于0");
        }
        this.price = price;
    }
    public String getProductId() { 
        return productId; 
    }
    public String getName() {
        return name; 
    }
    public double getPrice() { 
        return price; 
    }
    //用来获取商品描述（抽象类）
    public abstract String getDescription();
    
    public String toString() {
        return "商品编号: " + productId + ", 名称: " + name + ", 价格: " + price + ", 描述: " + getDescription();
    }
}
